package lzzy.com;
import Test.Student;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

// 线程作业--输出问候语和学生信息
public class ThreadJob {
    public static void main(String[] args) {
//        Runnable printA = new PrintGreetings("你好", 50);
//        Thread thread1 = new Thread(printA);
//        thread1.start();
//
        Student stu1 = new Student(1234,"wangwu");
        Student[] stus = {stu1};
        Runnable printStudent = new StudentFo(stus);
//        Thread thread = new Thread(printStudent);
//        thread.start();
//
//        Runnable printB = new PrintGreetings("拜拜", 50);
//        Thread thread2 = new Thread(printB);
//        thread2.start();

        ExecutorService executor = Executors.newFixedThreadPool(3);
        executor.execute(new PrintGreetings("你好", 50));
        executor.execute(new Thread(printStudent));
        executor.execute(new PrintGreetings("拜拜", 50));
        // 关闭线程池
        executor.shutdown();

    }
}
class PrintGreetings implements Runnable {
    private String stringToPrint; // The character to print 要打印的字符
    private int times; // The times to repeat 重复的时间

    public PrintGreetings(String c, int t) {
        stringToPrint = c;
        times = t;
    }
    @Override
    public void run() {
        for (int i = 0; i < times; i++) {
            System.out.print(stringToPrint);
        }
    }
}
class StudentFo implements Runnable{
    Student[] students;
    public StudentFo(Student[] students){
        this.students=students;
    }
    @Override
    public void run() {
        for(Student s:students){
            System.out.println(s);
        }
    }
}